package common.model.enums;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import common.model.po.SysUser;
import lombok.Getter;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 邮件通知类型枚举<br/>
 * 和数据库sys_user表中email_notify_types字段对应
 *
 * @author 米泽鹏
 * @since 2023-11-8 下午 6:35
 */
@Getter
public enum EmailNotifyTypeEnum {

	IMPORTANT_USER_INFO_MODIFIED(1, "用户重要信息变更"),

	PUSHED_OFF(2, "多端登录"),

	EMAIL_UNBOUND(3, "邮箱解绑"),

	ACCOUNT_DELETION(4, "账号删除"),

	COMMENT_ON_ME(5, "评论"),

	LIKE_ME(6, "点赞");

	/**
	 * 字段的值
	 */
	private final Integer value;

	/**
	 * 字段的描述
	 */
	private final String desc;

	EmailNotifyTypeEnum(Integer value, String desc) {
		this.value = value;
		this.desc = desc;
	}

	/**
	 * 检查用户是否已订阅该类型的通知，并且邮箱已激活
	 */
	public static boolean check(EmailNotifyTypeEnum emailNotifyTypeEnum, @NotNull SysUser user) {
		return check(emailNotifyTypeEnum, user.getEmail(), user.getEmailValid(), user.getEmailNotifyTypes());
	}

	/**
	 * 检查用户是否已订阅该类型的通知，并且邮箱已激活
	 */
	public static boolean check(EmailNotifyTypeEnum emailNotifyTypeEnum, String email, Integer emailValid, List<Integer> emailNotifyTypes) {
		return StrUtil.isNotBlank(email) && EmailValidEnum.VALID.getValue().equals(emailValid) && CollUtil.contains(emailNotifyTypes, emailNotifyTypeEnum.getValue());
	}

}
